<%@ page contentType="text/html; charset=utf-8"
 pageEncoding="utf-8" trimDirectiveWhitespaces="true" %>
<%@page import="untiring07.j2ee.basic.util.jdbc.MariaDB"%>
<%@page import="javax.sql.DataSource"%>
<%@page import="javax.naming.InitialContext"%>
<%@page import="javax.naming.Context"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.Connection"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Insert title here</title>
</head>
<body>
<h1>데이터베이스 커넥션 풀</h1>
<%
	String sql="select * from zipcode order by seq desc limit 0,100";
	Connection conn = null;
	PreparedStatement pstmt = null;
	ResultSet rs = null;
	
	try{
	//1.JNDI환경 설정
	// 컴퓨터 상의 자원을 java 언어를 이용해서 사용하기 위해 context를 설정함
	Context initCtx = new InitialContext();
	Context	ctx =(Context)initCtx.lookup("java:comp/env");
	
	//2. 데이터 베이스 서버를 JNDI로 호출
	DataSource ds=(DataSource)ctx.lookup("jdbc/zipcode");
	
	//3. 커넥션 풀로부터 연결 객체를 할당 받음
	conn = ds.getConnection();
	pstmt =conn.prepareStatement(sql);
	rs = pstmt.executeQuery();
	while(rs.next()){
		out.print(rs.getString(1)+" ");
	}
	}catch(Exception e){
		e.printStackTrace();
	}finally{
		MariaDB.closeConn(conn, pstmt, rs);
	}
	
	
	
	
	
%>

</body>
</html>